package com.ruoyi.web.controller.research;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.domain.TycResearchZd;
import com.ruoyi.service.ITycResearchZdService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 科研成果类型Controller
 * 
 * @author ruoyi
 * @date 2020-09-14
 */
@Controller
@RequestMapping("/ruoyi/rzd")
public class TycResearchZdController extends BaseController
{
    private String prefix = "ruoyi/rzd";

    @Autowired
    private ITycResearchZdService tycResearchZdService;

    @RequiresPermissions("ruoyi:rzd:view")
    @GetMapping()
    public String zd()
    {
        return prefix + "/rzd";
    }

    /**
     * 查询科研成果类型列表
     */
    @RequiresPermissions("ruoyi:rzd:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(TycResearchZd tycResearchZd)
    {
        startPage();
        List<TycResearchZd> list = tycResearchZdService.selectTycResearchZdList(tycResearchZd);
        return getDataTable(list);
    }

    /**
     * 导出科研成果类型列表
     */
    @RequiresPermissions("ruoyi:rzd:export")
    @Log(title = "科研成果类型", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(TycResearchZd tycResearchZd)
    {
        List<TycResearchZd> list = tycResearchZdService.selectTycResearchZdList(tycResearchZd);
        ExcelUtil<TycResearchZd> util = new ExcelUtil<TycResearchZd>(TycResearchZd.class);
        return util.exportExcel(list, "rzd");
    }

    /**
     * 新增科研成果类型
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存科研成果类型
     */
    @RequiresPermissions("ruoyi:rzd:add")
    @Log(title = "科研成果类型", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(TycResearchZd tycResearchZd)
    {
        return toAjax(tycResearchZdService.insertTycResearchZd(tycResearchZd));
    }

    /**
     * 修改科研成果类型
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        TycResearchZd tycResearchZd = tycResearchZdService.selectTycResearchZdById(id);
        mmap.put("tycResearchZd", tycResearchZd);
        return prefix + "/edit";
    }

    /**
     * 修改保存科研成果类型
     */
    @RequiresPermissions("ruoyi:rzd:edit")
    @Log(title = "科研成果类型", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(TycResearchZd tycResearchZd)
    {
        return toAjax(tycResearchZdService.updateTycResearchZd(tycResearchZd));
    }

    /**
     * 删除科研成果类型
     */
    @RequiresPermissions("ruoyi:rzd:remove")
    @Log(title = "科研成果类型", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(tycResearchZdService.deleteTycResearchZdByIds(ids));
    }
}
